

#import "EBMBaseWindowUpperView.h"

@implementation EBMBaseWindowUpperView



- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        /// 设置大小和背景颜色
        [self createViewInFrameAndBackgroundColor];
    }
    return self;
    
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    
    /// 设置大小和背景颜色
    [self createViewInFrameAndBackgroundColor];
    
}


/// 设置大小和背景颜色
- (void)createViewInFrameAndBackgroundColor
{
    self.frame = [UIScreen mainScreen].bounds;
    
    self.backgroundColor = RGBACOLOR16(@"000000", 0.7);
    
}



#pragma mark --------------方法--------------


/// 添加
- (void)addToWindow
{
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    
    [window addSubview:self];
    
    //  显示的动画
    [self showAnimation];
    
}


/// 移除
- (void)removeToWindow
{
    [self removeFromSuperview];
    
}


/// 添加点击事件
- (void)addTapGestureClick
{
    UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureClick:)];
    tapG.delegate = self;
    [self addGestureRecognizer:tapG];
}


//  显示的动画
- (void)showAnimation
{
    float scale = 0.8;
    
   CGAffineTransform newTransform =  CGAffineTransformScale(self.bgView.transform, scale, scale);
   [self.bgView setTransform:newTransform];
    
    
    [UIView animateWithDuration:0.15 animations:^{
        
        CGAffineTransform newTransform =  CGAffineTransformScale(self.bgView.transform, 1.0/scale, 1.0/scale);
        [self.bgView setTransform:newTransform];
        
    }];
    
    
   
}



#pragma mark --------------响应方法--------------


//  点击背景
- (void)tapGestureClick:(UITapGestureRecognizer *)tap
{
    [self removeToWindow];
    
}


#pragma mark ----------UITableViewDelegate 代理方法----------


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    UIView *touchView = touch.view;
    
    if([touchView isKindOfClass:[self class]])
    {
        return YES;
    }
    
    return NO;
}







@end
